﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Galoap
{
    public class PhratrisJSONEncoder : JSONEncoder
    {
        public string PartOfSpeechJSON { get; set; }

        public PhratrisJSONEncoder(Question q) {
            question = q;

            StringBuilder sb = new StringBuilder();
            foreach (Ontology on in ((PhratrisQuestion)q).PartOfSpeech)
            {
                sb.Append(on.ToString() + ",");
            }
            if ( ((PhratrisQuestion)q).PartOfSpeech.Length > 0) sb.Remove(sb.Length - 1, 1);
            PartOfSpeechJSON = sb.ToString();
        } 

        public override string GetJSON()
        {


            StringBuilder sb = new StringBuilder("\"partofspeech\":[" + PartOfSpeechJSON + "],");
            for (int i = 0; i < ((PhratrisQuestion)question).Tree.Length; i++)
            {
                sb.Append("\"tree_" + i + "\":[" + ((PhratrisQuestion)question).TreeString[i] + "],");
            }
            if (((PhratrisQuestion)question).Tree.Length > 0) sb.Remove(sb.Length - 1, 1);
            return "{" + base.GetJSON() + ",\"subclass\":{" + sb.ToString() + "}" +  "}";
        }

    }
}
